<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('customer_id')->comment('客户ID');
            $table->string('sku', 60)->comment('产品SKU');
            $table->string('name', 250)->comment('产品名称');
            $table->char('unit', 3)->comment('产品单位');
            $table->char('condition', 3)->comment('存储条件');
            $table->char('validity', 3)->comment('需要进行效期管理');
            $table->integer('lockup_validity')->default(0)->comment('保质期禁售天数');
            $table->char('lock_status', 3)->default(0)->comment('状态: 0 未锁定; 1 已锁定;');
            $table->char('status', 3)->default(0)->comment('状态: 0 草稿; 1 正常;');
            $table->unique(['sku', 'customer_id']);
            $table->timestamps();
        });

        Schema::create('product_inventories', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('product_id')->unique()->comment('产品ID');
            $table->unsignedInteger('usable')->comment('可用数量')->default(0);
            $table->unsignedInteger('unusable')->comment('不可用数量')->default(0);
            $table->unsignedInteger('lock')->comment('锁定数量')->default(0);
            $table->unsignedInteger('outbound')->comment('已出库数量')->default(0);
            $table->timestamps();
        });

        Schema::create('product_volume', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('product_id');
            $table->integer('length')->comment('长 毫米');
            $table->integer('width')->comment('宽 毫米');
            $table->integer('height')->comment('高 毫米');
            $table->integer('weight')->comment('重量 千克');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
        Schema::dropIfExists('product_inventories');
        Schema::dropIfExists('product_volume');
    }
}
